package com.fzshang.shopping.wx.controller;


import com.fzshang.shopping.commen.bean.Feedback;
import com.fzshang.shopping.commen.controller.BaseController;
import com.fzshang.shopping.commen.entity.ApiResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 建议反馈 前端控制器
 * </p>
 *
 * @author 冯政尚
 * @since 2020-03-12
 */
@Controller
@RequestMapping("wx/feedback")
public class WXFeedbackController extends BaseController {

    /**
     * @param
     * @return 意见反馈
     */
    @RequestMapping(value = "feedback.html")
    public String feedback(Model model, HttpServletRequest request){
        model.addAttribute("user",getWxUser(request));
        model.addAttribute("feedbackClassification",feedbackClassificationService.list());
        return "wx/personal/feedback";
    }

    /**
     * @param feedback
     * @return 添加
     */
    @RequestMapping(value = "save")
    @ResponseBody
    public ApiResult save(@RequestBody Feedback feedback){
        feedback.setCreateTime(System.currentTimeMillis());
        feedback.setState(2);
        if(feedbackService.save(feedback)){
            return ApiResult.ok();
        }
        return ApiResult.fail();
    }
}
